package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import view.user.Login;
import view.user.TotalAmount;
import view.user.Withdrawal;
import view.user.Menu;
import model.ModelClass;
import controller.ColorChanger;
import controller.KeyHandler;
import controller.SkinChanger;
import controller.TableHandler;
import controller.SlideHandler;
import controller.ActionEvents.ActionHandler;
/**
 * 
 * @author Christian
 * Class MainFrame represents the Frame around the CardLayout by extending JFrame.
 */
public class MainFrame extends JFrame {

	/** Declares the classes as an object */
	private Menu menu;
	private CenterPanel centerPanel;
	private Login login;
	private ModelClass modelClass;
	private ActionHandler actionHandler;
	private TotalAmount totalAmount;
	private Withdrawal withdrawal;
	private AdminPanel adminPanel;
	private TableHandler tableHandler;
	private KeyHandler keyHandler;
	private SlideHandler slideHandler;
	private OptionPanes optionPanes;
	private SkinChanger skinChanger;
	private ColorChanger colorChanger;

	
	/**
	 * Constructor creates the frame by using BorderLayout.
	 */
	public MainFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 750, 500);
		setResizable(false);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setBackground(Color.WHITE);
		getContentPane().setLayout(new BorderLayout(0, 0));
		
		actionHandler = new ActionHandler(this);
		modelClass =  new ModelClass();
		tableHandler = new TableHandler(this);
		keyHandler = new KeyHandler(this);
		slideHandler = new SlideHandler(this);
		optionPanes = new OptionPanes(this);
		skinChanger = new SkinChanger(this);
		colorChanger = new ColorChanger(this);
		
		
		/** Adds the login CardLayout to BorderLayout west.
		 *@note login CardLayout is set to west due to BorderLayout can't contain multiple JPanels in center*/
		login = new Login(actionHandler);
		login.setVisible(true);
		getContentPane().add(login,BorderLayout.WEST);
		
		/** Adds the menu CardLayout to BorderLayout NORTH*/
		menu = new Menu(actionHandler);
		menu.setVisible(false);
		getContentPane().add(menu,BorderLayout.NORTH);
		
		/** Adds the container CenterPanel to BorderLayout center*/
		centerPanel = new CenterPanel(actionHandler, slideHandler, keyHandler);
		centerPanel.setVisible(false);
		getContentPane().add(centerPanel,BorderLayout.CENTER);
		
		/** Adds the amount CardLayout to BorderLayout west*/
		totalAmount = new TotalAmount(actionHandler);
		totalAmount.setVisible(false);
		getContentPane().add(totalAmount, BorderLayout.SOUTH);
		
		
		adminPanel = new AdminPanel(actionHandler, tableHandler, keyHandler);
		adminPanel.setVisible(false);
		getContentPane().add(adminPanel, BorderLayout.EAST);
		

		
getSkinChanger().changeLoginSkin();
	}
	
	/**
	 * @return the skinChanger
	 */
	public SkinChanger getSkinChanger() {
		return skinChanger;
	}

	/**
	 * @param skinChanger the skinChanger to set
	 */
	public void setSkinChanger(SkinChanger skinChanger) {
		this.skinChanger = skinChanger;
	}

	/** Is invoked whenever user login. The method 'disables' the login JPanel, and 'enables' menu, centerPanel, and amount*/
	public void LoginTrue()
	{
		login.setVisible(false);
		menu.setVisible(true);
		centerPanel.setVisible(true);
		totalAmount.setVisible(true);
		adminPanel.setVisible(false);
		
		
	}
	
	/** Is invoked whenever user logs off. the method converses above LoginTrue()*/
	public void LoginFalse()
	{
		login.setVisible(true);
		menu.setVisible(false);
		centerPanel.setVisible(false);
		totalAmount.setVisible(false);
		adminPanel.setVisible(false);
	}
	
	public void adminLoginTrue()
	{
		login.setVisible(false);
		menu.setVisible(false);
		centerPanel.setVisible(false);
		totalAmount.setVisible(false);
		adminPanel.setVisible(true);
		
	}
	
	public void adminLoginFalse()
	{
		login.setVisible(true);
		menu.setVisible(false);
		centerPanel.setVisible(true);
		totalAmount.setVisible(false);
		adminPanel.setVisible(false);
		
	}
	
	/**
	 * @return the centerPanel
	 */
	public CenterPanel getCenterPanel() 
	{
		return centerPanel;
	}

	/**
	 * @param centerPanel the centerPanel to set
	 */
	public void setCenterPanel(CenterPanel centerPanel) 
	{
		this.centerPanel = centerPanel;
	}
	
	/**
	 * @return the menu
	 */
	public Menu getMenu() 
	{
		return menu;
	}
	
	/**
	 * @param menu the menu to set
	 */
	public void setMenu(Menu menu) 
	{
		this.menu = menu;
	}
	
	/**
	 * @return the login
	 */
	public Login getLogin() 
	{
		return login;
	}
	
	/**
	 * @param login the login to set
	 */
	public void setLogin(Login login) 
	{
		this.login = login;
	}
	
	/**
	 * @return the modelClass
	 */
	public ModelClass getModelClass() 
	{
		return modelClass;
	}
	
	/**
	 * @param modelClass the modelClass to set
	 */
	public void setModelClass(ModelClass modelClass) 
	{
		this.modelClass = modelClass;
	}
	
	/**
	 * @return the ac
	 */
	public ActionHandler getAc() 
	{
		return actionHandler;
	}
	
	/**
	 * @param ac the ac to set
	 */
	public void setAc(ActionHandler ac) 
	{
		this.actionHandler = ac;
	}
	
	/**
	 * @return the totalAmount
	 */
	public TotalAmount getTotalAmount() 
	{
		return totalAmount;
	}
	
	/**
	 * @param totalAmount the saldo to set
	 */
	public void setTotalAmount(TotalAmount totalAmount) 
	{
		this.totalAmount = totalAmount;
	}
	
	/**
	 * @return the withdrawal
	 */
	public Withdrawal getWithdrawal() 
	{
		return withdrawal;
	}
	
	/**
	 * @param withdrawal the withdrawal to set
	 */
	public void setWithdrawal(Withdrawal withdrawal) 
	{
		this.withdrawal = withdrawal;
	}

	/**
	 * @return the adminPanel
	 */
	public AdminPanel getAdminPanel() {
		return adminPanel;
	}

	/**
	 * @param adminPanel the adminPanel to set
	 */
	public void setAdminPanel(AdminPanel adminPanel) {
		this.adminPanel = adminPanel;
	}

	/**
	 * @return the optionPanes
	 */
	public OptionPanes getOptionPanes() {
		return optionPanes;
	}

	/**
	 * @return the slideHandler
	 */
	public SlideHandler getSlideHandler() {
		return slideHandler;
	}

	/**
	 * @param slideHandler the slideHandler to set
	 */
	public void setSlideHandler(SlideHandler slideHandler) {
		this.slideHandler = slideHandler;
	}

	/**
	 * @return the colorChanger
	 */
	public ColorChanger getColorChanger() {
		return colorChanger;
	}

	/**
	 * @param colorChanger the colorChanger to set
	 */
	public void setColorChanger(ColorChanger colorChanger) {
		this.colorChanger = colorChanger;
	}
	

} // End class MainFrame.java
